version 10.0
log using "C:\fsu2010\formateur\ajps\submission2\replication\analysis\IIAtest_rand.log", replace
#delimit ;

set more off;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:  IIAtest_rand.do                                     *;
*       Date:       November 11, 2010                                   *;
*       Author:     MRG                                                 *;
*       Purpose:    Do Hausman tests on europe.dta                      *;
*       Input File:     europe.dta                                      *;
*       Output File:    IIAtest.log                                     *;
*       Data Output:    none                                            *;
*       Previous file:  europe.dta                                      *;
*       Machine:        Matt's desktop                                  *;
*     ****************************************************************  *;
*     ****************************************************************  *;

use "C:\fsu2010\formateur\ajps\submission2\replication\analysis\europe.dta", clear;

*     ****************************************************************  *;
*       IIA test dropping one party at a time.                          *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Drop missing observations to ensure Hausman tests are valid     *;
*     ****************************************************************  *;

drop if previousPM_conflict==.;
drop if previousPM_gain==.; 

*     ****************************************************************  *;
*       Generate counter variable for formation opportunity             *;
*     ****************************************************************  *;

egen cabcount = group(cabinetcode);

xtset cabinetcode partyID;
xtdescribe;
sum; 

*     ****************************************************************  *;
*       Model 6 using clogit.                                           *;
*     ****************************************************************  *;

clogit choice largestparty party_seatshare medianparty1 presidentparty previousPM president_investiture 
        president_direct previousPM_conflict previousPM_gain1 previous_cabinet_gain1
        largestparty_east party_seatshare_east medianparty1_east presidentparty_east previousPM_east 
        previousPM_conflict_east previousPM_gain1_east previous_cabinet_gain1_east,  
        group(cabinetcode);

estimates store A;

generate chi2_rand = .;
generate df_rand = .;
generate p_rand = .;

generate dropcab = 0;

generate seldrop = .;

local n = 1;  /* index for observations */

local i = 1;
while `i'<101{;

  qui replace seldrop = uniform();
  qui replace dropcab = 1 if seldrop < 0.1;

  qui clogit choice largestparty party_seatshare medianparty1 presidentparty previousPM president_investiture 
        president_direct previousPM_conflict previousPM_gain1 previous_cabinet_gain1
        largestparty_east party_seatshare_east medianparty1_east presidentparty_east previousPM_east 
        previousPM_conflict_east previousPM_gain1_east previous_cabinet_gain1_east 
        if dropcab!=1, group(cabinetcode); 

  estimates store B;
  qui hausman B A, alleqs constant;
  qui replace chi2_rand = r(chi2) if _n==`n';
  qui replace df_rand = r(df) if _n==`n';
  qui replace p_rand = r(p) if _n==`n';
  qui replace dropcab = 0;
  local i = `i' + 1;
  local n = `n' + 1;

};
  


*     ****************************************************************  *;
*       Bonferroni corrections                                          *;
*     ****************************************************************  *;

egen ntest_rand = count(chi2_rand);

generate U_p_rand = p_rand*0;
replace U_p_rand = 1 if p_rand<(0.05);

generate Bc_p_rand = p_rand*0;
replace Bc_p_rand = 1 if p_rand<(0.05/ntest_rand);

*     ****************************************************************  *;
*       Display results                                                 *;
*     ****************************************************************  *;

ta Bc_p_rand;
ta U_p_rand;

egen pmean = mean(p_rand);
sum pmean;


